import 'package:tender_flutter/page/track/model/track_entity.dart';

trackEntityFromJson(TrackEntity data, Map<String, dynamic> json) {
	if (json['pageNum'] != null) {
		data.pageNum = json['pageNum'] is String
				? int.tryParse(json['pageNum'])
				: json['pageNum'].toInt();
	}
	if (json['pageSize'] != null) {
		data.pageSize = json['pageSize'] is String
				? int.tryParse(json['pageSize'])
				: json['pageSize'].toInt();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['pages'] != null) {
		data.pages = json['pages'] is String
				? int.tryParse(json['pages'])
				: json['pages'].toInt();
	}
	if (json['list'] != null) {
		data.xList = new List<TrackList>();
		(json['list'] as List).forEach((v) {
			data.xList.add(new TrackList().fromJson(v));
		});
	}
	if (json['isFirstPage'] != null) {
		data.isFirstPage = json['isFirstPage'];
	}
	if (json['isLastPage'] != null) {
		data.isLastPage = json['isLastPage'];
	}
	return data;
}

Map<String, dynamic> trackEntityToJson(TrackEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['pageNum'] = entity.pageNum;
	data['pageSize'] = entity.pageSize;
	data['total'] = entity.total;
	data['pages'] = entity.pages;
	if (entity.xList != null) {
		data['list'] =  entity.xList.map((v) => v.toJson()).toList();
	}
	data['isFirstPage'] = entity.isFirstPage;
	data['isLastPage'] = entity.isLastPage;
	return data;
}

trackListFromJson(TrackList data, Map<String, dynamic> json) {
	if (json['creditCode'] != null) {
		data.creditCode = json['creditCode'].toString();
	}
	if (json['companyName'] != null) {
		data.companyName = json['companyName'].toString();
	}
	if (json['companyKey'] != null) {
		data.companyKey = json['companyKey'].toString();
	}
	if (json['logo'] != null) {
		data.logo = json['logo'].toString();
	}
	if (json['companyID'] != null) {
		data.companyID = json['companyID'] is String
				? int.tryParse(json['companyID'])
				: json['companyID'].toInt();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	return data;
}

Map<String, dynamic> trackListToJson(TrackList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['creditCode'] = entity.creditCode;
	data['companyName'] = entity.companyName;
	data['companyKey'] = entity.companyKey;
	data['logo'] = entity.logo;
	data['companyID'] = entity.companyID;
	data['id'] = entity.id;
	return data;
}